#include <Arduino.h>
#include "ESP8266WiFi.h"
#include "ESP8266WebServer.h"

ESP8266WebServer server(80);

const int LED =4;
//设置网页
void handleRoot(){
String html="<!DOCTYPE html>"
"<html>"
"<head>"
    "<meta charset=\"utf-8\" />"
    "<title>网页控制单片机</title>"
"</head>"
"<body>"
    "<h1>局域网控制</h1>"
    "<div>"
        "<a href=\"/on\" >打开led</a>"
        "<a href=\"/off\" >关闭led</a>"
    "</div>  "
"</body>"
"</html>";
server.send(200,"text/html",html);
}
//开启
void handleOn(){
  digitalWrite(LED,LOW);
  server.sendHeader("Location","/");
  server.send(303);
}
//关闭
void handleOff(){
digitalWrite(LED,HIGH); 
 server.sendHeader("Location","/");
  server.send(303);
}
//找不到
void handleNotFound(){
 server.send(200,"text/plain","not found");
}
void setup() {
  //打开串口
  Serial.begin(15200);
  //热点模式
  WiFi.mode(WIFI_AP);
  //热点名，密码
  WiFi.softAP("local-led","12345678");
  //led 输出模式
  pinMode(LED,OUTPUT);
   
   server.begin();
   server.on("/",handleRoot);
   server.on("/on",handleOn);
   server.on("/off",handleOff);
   server.onNotFound(handleNotFound);
}

void loop() {
   server.handleClient();
}
